﻿
@{
    Layout = null;
}


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="~/layui-v2.6.8/layui/layui.js"></script>
</head>
<body>

    <form class="layui-form" action="" id="AddForm">
        <div class="layui-form-item">
            <label class="layui-form-label">ID:</label>
            <div class="layui-input-inline">
                <input type="text" name="uidd" id="uidd" lay-verify="required" placeholder="请输入用户ID:" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名编号:</label>
            <div class="layui-input-inline">
                <input type="text" name="ubh" id="ubh" lay-verify="required" placeholder="请输入用户名:" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">用户名:</label>
            <div class="layui-input-inline">
                <input type="text" name="userName" id="userName" lay-verify="required" placeholder="请输入用户名:" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码:</label>
            <div class="layui-input-inline">
                <input type="password" name="userPwd" id="userPwd" lay-verify="required" placeholder="请输入密码:" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="uname" id="uname" lay-verify="required" placeholder="请输入用户名:" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户性别:</label>
            <div class="layui-input-block">
                <input type="radio" name="usex" id="usex" value="男" title="男" checked="">
                <input type="radio" name="usex" id="usex" value="女" title="女">
                <input type="radio" name="usex" id="usex" value="禁" title="禁用" disabled="">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">职位</label>
            <div class="layui-input-inline">
                <select name="utype" id="utype" lay-filter="aihao">
                    <option >===请选择===</option>
                    <option value="秘书">秘书</option>
                    <option value="主管">主管</option>
                    <option value="人事">人事</option>
                    <option value="员工">员工</option>
                    <option value="测试">测试</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">用户QQ:</label>
            <div class="layui-input-inline">
                <input type="text" name="uqq" id="uqq" lay-verify="required" placeholder="请输入QQ:" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">注册日期</label>
                <div class="layui-input-block">
                    <input type="text" name="utime" id="utime" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" name="close" lay-skin="switch" lay-text="在线|离线">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>


    <script src="~/lib/jquery/dist/jquery.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script>
        ///反填
        $().ready(function () {//文档就绪函数
            $.ajax({
                url: 'http://localhost:36862/api/Userinfou/Fan?id=' +@ViewBag.id,
                success: function (d) {
                    $("#uidd").val(@ViewBag.id);
                    $("#ubh").val(d.data.ubh);
                    $("#userName").val(d.data.userName);
                    $("#userPwd").val(d.data.userPwd);
                    $("#uname").val(d.data.uname);
                    $("#usex").val(d.data.usex);
                    $("#utype").val(d.data.utype);
                    $("#uqq").val(d.data.uqq);
                    $("#utime").val(d.data.utime)
                }
            })
        })
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            //日期
            laydate.render({
                elem: '#utime'
            });
            laydate.render({
                elem: '#utime'
            });
            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');
            //自定义验证规则
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                }
                , pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
                , content: function (value) {
                    layedit.sync(editIndex);
                }
            });
            //监听指定开关
            form.on('switch(switchTest)', function (data) {
                layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                    offset: '6px'
                });
                layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
            });

            //监听提交
            form.on('submit(demo1)', function (data) {
                $.ajax({
                    url: 'http://localhost:36862/api/Userinfou/Upt',
                    type: 'post',
                    /*data: $("#AddForm").serialize(),*/
                    data: data.field,
                    success: function (a) {
                        if (a > 0) {
                            layer.msg("修改成功", { time: 2000, icon: 1 }, function () {
                                parent.location.href = '/TmT/Show'
                            });
                        }
                        else {
                            layer.msg("修改失败", { time: 2000, icon: 5 }, function () {
                                parent.location.href = '/TmT/Show'
                            });
                        }
                    }
                })
                return false;
            });


            //表单赋值
            layui.$('#LAY-component-form-setval').on('click', function () {
                form.val('example', {
                    "username": "贤心" // "name": "value"
                    , "password": "123456"
                    , "interest": 1
                    , "like[write]": true //复选框选中状态
                    , "close": true //开关状态
                    , "sex": "女"
                    , "desc": "我爱 layui"
                });
            });

            //表单取值
            layui.$('#LAY-component-form-getval').on('click', function () {
                var data = form.val('example');
                alert(JSON.stringify(data));
            });

        });
    </script>

</body>
</html>